package cn.edu.scau.cmi.zhangxiyang.SpringandHibernate;

import org.hibernate.Session;
import java.util.List;  
import org.hibernate.HibernateException;  
import org.hibernate.Session;  
import org.hibernate.SessionFactory;  
import org.hibernate.Transaction;  
import org.hibernate.cfg.Configuration;  
import org.hibernate.criterion.Example;  

public class BaseHibernateDAO {
	
	private static Session session=null;  
	private static SessionFactory sf; 
	
	public static Session getSession(){  
		  if(session!=null){  
			  return session;  
		  }  
		  else if(sf!=null){  
			  session=sf.openSession();  
		  	return session;  
		  }  
		  Configuration cfg=new Configuration().configure("/hibernate.cfg.xml");
		  sf=cfg.buildSessionFactory();  
		  session=sf.openSession();
		  /*Transaction tx = session.beginTransaction();
		  tx.commit();
		  tx.rollback();*/
		  return session;  
	}

}
